﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KongMing.ORM.EFCore.EFModelExtension
{
    public static class OutSoftsEFExtension
    {
        public static void AddOutSoftsPreFix(this ModelBuilder modelBuilder, IEnumerable<Type> modelTypes)
        {
            var useTypes = modelTypes.Where(x => x.GetCustomAttributes(typeof(OutSoftsPreFixAttribute), false).Any());
            foreach (var type in useTypes)
            {
                foreach (var p in type.GetProperties())
                    modelBuilder.Entity(type).Property(p.Name).HasColumnName($"f_{p.Name.ToLower()}");
            }
        }
    }
}
